package com.gainloop.Api.Entity;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.Gson;

public abstract class EntityAbstract {
	
	protected static Gson _gson = new Gson();
	
	public static <T extends EntityAbstract> T fromObject(JSONObject obj, Class<T> entityClass)
	{
		if(obj == null)
			return null;
		
		return _gson.fromJson(obj.toString(), entityClass);
	}

	public JSONObject toObject() throws JSONException
	{
		return new JSONObject(_gson.toJson(this));
	}
	
}
